package com.oren.system.ctrl;

import com.oren.base.ctrl.BaseController;
import com.oren.base.pojo.Tree;
import com.oren.system.pojo.Menu;
import com.oren.system.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: oren
 * @Description:
 * @Date: Create on 2017/11/8 0008 14:35
 */
@Controller
@RequestMapping("/menu")
public class MenuController  extends BaseController {
	@Autowired
	private MenuService menuService;

	@RequestMapping("/listMenu")
	@ResponseBody
	public Map<String ,Object> listMenu(HttpServletRequest request)throws Exception{
		String userName=getSessionUserName(request);
		List<Menu> list=menuService.listMenu();
		Map<String ,Object> map=new HashMap<String ,Object>();
		map.put("list",list);
		map.put("username",userName);
		return map;
	}

	@RequestMapping("/treeList")
	@ResponseBody
	public List<Tree> listMenuTree(HttpServletRequest request)throws Exception{
		String parentId=request.getParameter("id");
		return  menuService.listTreeMenu(parentId);
	}


}
